﻿using System;
using HttpApiGateway;
using HttpApiGateway.Model;
using RpcClient;
using RpcHelper.Validate;
using Wedonek.RpcStore.Gateway.Interface;
using Wedonek.RpcStore.Gateway.Model;
using Wedonek.RpcStore.Service.Model;
namespace Wedonek.RpcStore.Gateway.Controller
{
    /// <summary>
    /// 资源
    /// </summary>
    internal class ResourceController : ApiController
    {
        private readonly IResourceService _Resource;

        public ResourceController(IResourceService resource)
        {
            this._Resource = resource;
        }
        /// <summary>
        /// 取消屏蔽
        /// </summary>
        /// <param name="resourceId"></param>
        public void Cancel([NullValidate("rpc.resource.id.null")] Guid resourceId)
        {
            this._Resource.CancelShieId(resourceId);
        }
        /// <summary>
        /// 获取资源屏蔽的过期时间
        /// </summary>
        /// <param name="resourceId"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public DateTime? GetBeOverTime([NullValidate("rpc.resource.id.null")] Guid resourceId)
        {
            return this._Resource.GetBeOverTime(resourceId);
        }

        /// <summary>
        /// 查询资源
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public PagingResult<ResourceDatum> Query(PagingParam<ResourceQueryParam> param)
        {
            ResourceDatum[] list= this._Resource.Query(param.Param, param.ToBasicPaging(), out long count);
            return new PagingResult<ResourceDatum>(list, count);
        }

        /// <summary>
        /// 资源屏蔽
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public long ShieId(GuidNullParam<DateTime?> param)
        {
            return this._Resource.ResourceShieId(param.Id, param.Param);
        }
        /// <summary>
        /// 设置屏蔽的过期时间
        /// </summary>
        /// <param name="obj"></param>
        public void SetBeOverTime(GuidNullParam<DateTime?> obj)
        {
            this._Resource.SetBeOverTime(obj.Id, obj.Param);
        }
    }
}
